// pages/barbecue/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: false,
    curNav: 1,
    curIndex: 0,
    cart: [],
    cartTotal: 0,
    navList: [
      {
        id: 1,
        name: '课后练习',
        action:'/app/course/exercise/user/findPage'
      },
     /* {
        id: 3,
        name: '专项练习'
      }*/,
      {
        id: 2,
        name: '模拟考试',
        action: '/app/mockexam/theory/user/listData'
      }
    ],
    dishesList: [],
    courseExercise:{},
    mockexamTheory:{},
    dishes: [],
    height: 0,
    cours:{},
    server:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })
      }
    })
    this.loadingChange()
    var _this = this;
    app.paiRequest("/app/course/exercise/user/findPage", {pageNo: 1, pageSize: 7 }).then(function (res) {
      var data=res.data;
      
      _this.setData({
        courseExercise: data,
        server:app.data.server
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  loadingChange: function () {
    setTimeout(() => {
      this.setData({
        hidden: true
      })
    }, 2000)
  },
  selectNav: function (event) {
    let id = event.target.dataset.id, index = parseInt(event.target.dataset.index);
    var action=event.currentTarget.dataset.action;
    self = this;
    this.setData({
      curNav: id,
      curIndex: index
    })
    var dishesList = this.data.dishesList;
    if (action!=undefined){
      app.paiRequest(action, { pageNo: 1, pageSize: 7}).then(function (res) {
        console.log(res);
        
        self.setData({
          courseExercise: res.data
        })
      })
    }
  },
  setStatus(dishId) {
    let dishes = this.data.dishesList;
    for (let dish of dishes) {
      dish.forEach((item) => {
        if (item.id == dishId) {
          item.status = !item.status || false
        }
      })
    }

    this.setData({
      dishesList: this.data.dishesList
    })
  },
  selectTap: function (e) {
    console.log(e);
    var dataset = e.currentTarget.dataset;
    var src = dataset.src;
    var obj = JSON.stringify(dataset);
    wx.navigateTo({
      url: src + '?dataset=' + obj,
    })
  },
  detailpage: function (e) {
    var dataset = e.currentTarget.dataset;
    var src = dataset.src;
    var obj = JSON.stringify(dataset);
    wx.navigateTo({
      url: src + '?dataset=' + obj,
    })
  },
  detailNav:function(e){
    console.log(e);
    var dataset = e.currentTarget.dataset;
    var src = dataset.src;
    var exercisesId=dataset.id;
    var courseId = dataset.courseid;
    var courseHourseId = dataset.coursehourseid;
    var coursehoursetitle = dataset.titlename;
    var pageSource = dataset.pagesource;
    debugger
    src = src + "?parentCode=" + courseHourseId;
    src = src + "&exercisesId=" + exercisesId + "&courseId=" + courseId + "&courseHourseId=" + courseHourseId
        + "&coursetitle=" + coursehoursetitle+"&questionPageSource="+pageSource;
    wx.navigateTo({
      url: src,
    })
  },
  mocktheory:function(e){
    var dataset = e.currentTarget.dataset;
    var src = dataset.src;
    src = src + '?title=' + dataset.titlename + '&id=' + dataset.id;
    wx.navigateTo({
      url: src,
    })
  },
  navigatTo:function(e){
    var src = e.currentTarget.dataset.src;
    wx.navigateTo({
      url: src,
    })
  }
})